// 动态生成表格
function renderTable(data) {
  $('#student-table tbody').text('');
  for (var i = 0; i < data.length; i++) {
    var tr = `
      <tr>
          <td><input type="checkbox" class="book-state"></td>
          <td>${data[i].studentName}</td>
          <td>${data[i].className}</td>
          <td>
            <button type="button" class="layui-btn" data-bookid="${data[i].studentId}">查看</button>
            <button class="layui-btn layui-btn-normal edit" data-bookid="${data[i].studentId}">编辑</button>
            <button type="button" class="layui-btn layui-btn-danger del" data-bookid="${data[i].studentId}">删除</button>
          </td>
        </tr>
    `;
    $('#student-table tbody').append($(tr));
  }
}

function initStudent() {
  $.ajax({
    url: '/students/get',
    method: 'GET',
  })
    .done(function (res) {
      console.log('请求成功：', res);

      renderTable(res.data);
    })
    .fail(function (err) {
      console.log('请求失败：', err);
    });
}
initStudent();